﻿using System;
using Core.Mgr;
using Core.Mgr._Timer;
using UnityEngine;

namespace Logic.Global
{
    /// 震动工具
    public static class VibrateTool
    {
        private static int _curTimerId = -1;

        /// 连续震动
        public static void VibrateContinuous(this MonoBehaviour mono)
        {
            if (!SetDataModel.VibrateOn) return;
            if (!_curTimerId.Equals(-1)) return;
#if UNITY_IOS
            _curTimerId = mono.StartTimer(delegate
            {
                //
                PluginMgr.Ins.VibratorWave(300, 80);
            }, 0, -1, 0.3f);
#elif UNITY_ANDROID
            _curTimerId = mono.StartTimer(delegate
            {
                //
                PluginMgr.Ins.VibratorWave(5000, 80);
            }, 0, -1, 5f);
#endif
        }

        private static DateTime _preVibrate = DateTime.MinValue;

        /// 瞬间震动
        public static void VibrateTransient(int millsecond = 100, int amplitude = 200)
        {
            if (!SetDataModel.VibrateOn) return;
            PluginMgr.Ins.VibratorOnce(millsecond, amplitude);
        }

        /// 停止连续震动
        public static void Stop()
        {
            TimerMgr.EndTimer(_curTimerId);
            _curTimerId = -1;
            PluginMgr.Ins.StopWaveVibrator();
        }
    }
}